<template>
	<view>
		
		<view class='share-box' :class="showModal ? '' : 'hide'">
			<view class='choose'>
				<view class="main-content">
					
					<view>
						<view  class="input-item">
							<label>菜品内容（{{item.date}}{{item.weekName}})
							
							<text v-if="type == 0">早餐</text>
							<text v-else-if="type == 1">午餐</text>
							<text v-else-if="type == 2">晚餐</text>
							</label>
							<view class="projects">
								<block v-for="(item,index) in project">
									<view class="item" :class="index == projectIndex ? 'active' : ''">{{item.name}}</view>
								</block>
							</view>
							<view><textarea  class="content" v-model="content" placeholder="请输入菜品内容"></textarea></view>
						</view>
						<view class="confirm" @click="confirm">保存</view>
					</view>
				</view>
				<view style="padding: 0 40%;" @click='close' class="iconfont icon icon-guanbi close"></view>
			</view>
			<view :class="showModal ? 'maskLayer' : ''" @click='close'></view>
		</view>
		
	</view>
</template>

<script>

	import {
		menuAdd
	} from '@/api/merchant/menu.js';
	export default {
		name:'jhxRestaurantMenu',
		components: {
		},
		props: {   

		},
		data() {
			return {
				item:{},
				type:0,
				showModal:false,
				content:'',
				parentIndex:'',
				id:'',
				project:[
					{name:'方案一',id:0},
					{name:'方案二',id:1}
				],
				projectIndex:0
			}
		},
		created() {
			
		},
		watch:{
			
		},
		methods:{
			confirm:function(){
				var that = this;
				var param={
					content:this.content,
					date:this.item.date,
					type:this.type,
					id:this.id,
					project:this.project[this.projectIndex].id
				}
				this.$http.post(`${menuAdd}`, {
					...param
				})
				.then(async res => {
					if(res.code == 200){
						uni.showToast({
							title:'保存成功'
						})
						if(that.projectIndex == 0){
							if(that.type == 0){
								that.item.first.morning = res.data;
							}
							if(that.type == 1){
								that.item.first.noon = res.data;
							}
							if(that.type == 2){
								that.item.first.evening = res.data;
							}
						}else if(that.projectIndex == 1){
							if(that.type == 0){
								that.item.second.morning = res.data;
							}
							if(that.type == 1){
								that.item.second.noon = res.data;
							}
							if(that.type == 2){
								that.item.second.evening = res.data;
							}
						}
						
						that.$emit('success',{'data':that.item,'index':that.parentIndex})
						that.close();
					}else{
						uni.showToast({
							icon:'none',
							title:res.msg ? res.msg : '保存失败'
						})
					}
				})
			},
			//关闭快递公司选择页面
			open:function(item,type,log,parentIndex,projectIndex){
				this.item= item;
				this.type = type;
				this.content = log && log.content ? log.content : '';
				this.id = log && log.id ? log.id : '';
				this.parentIndex = parentIndex;
				this.projectIndex = projectIndex;
				console.log(this.projectIndex);
				this.showModal=true 
			},
			close:function(){
				this.showModal=false;
			},
		}
	}
</script>

<style lang="scss">
	.choose{width:80%;-webkit-animation: spin .2s linear ;animation: spin .2s linear;position: fixed;top: 20%;left:10%;z-index: 991;}
	.main-content{background-color: #fff;padding: 40rpx 20rpx;border-radius: 10rpx;}
	.close{color: #f9f9f9;margin-top: 40rpx;text-align: center;font-size: 80rpx;}
	.closeTab{color: #f9f9f9;margin-top: 100rpx;text-align: center;font-size: 80rpx;position: fixed;bottom: 80rpx;text-align: center;width: 100%;}
	.content{border: 1px solid #ccc;width: 96%;margin:40rpx 0;padding: 20rpx;box-sizing: border-box;}
	.confirm{padding: 20rpx;background-color: #ff6600;color: #fff;text-align: center;border-radius: 60rpx;}
	.maskLayer{z-index: 99;}
	.hide{display: none;}
	.projects{
		display: flex;margin-top: 20rpx;
		.item{width: 200rpx;padding: 25rpx 0;text-align: center;border: 1px solid #ececec; margin-right: 30rpx;border-radius: 10rpx;}
		.active{background-color:#ff6600; color: #fff;}
	}
</style>
